//
//  XLMyLevelViewController.m
//  XiangLove
//
//  Created by 李传坤 on 2018/3/27.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLMyLevelViewController.h"
#import "XLWebViewController.h"
#import "XLHTTPSessionManager.h"
#import "XLAccountManager.h"
#import <ReactiveCocoa.h>
#import "XLLevelInforModel.h"
#import "XLLevelUpSheetView.h"
#import "XLGetAwardSheetView.h"
@interface XLMyLevelViewController ()

//宽度设置
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *progressViewWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *pointViewOffSet;

//我的积分（距离LV。5还差200经验值）
@property (weak, nonatomic) IBOutlet UILabel *MyJifenNumberLabel;

//等级图片
@property (weak, nonatomic) IBOutlet UILabel *labelOnImage;

//距离升级所差积分
@property (weak, nonatomic) IBOutlet UILabel *centerLevel;

//当前等级
@property (weak, nonatomic) IBOutlet UILabel *currentLevel;

//下个等级
@property (weak, nonatomic) IBOutlet UILabel *nextLevel;

//
@property (weak, nonatomic) IBOutlet UILabel *progressView;

//详情

//1 等级特权
@property (weak, nonatomic) IBOutlet UILabel *teQunLbl;

@property (weak, nonatomic) IBOutlet UILabel *TwoLbl;

@property (weak, nonatomic) IBOutlet UILabel *ThreLbl;

@property (weak, nonatomic) IBOutlet UILabel *FourLbl;

//如何提升等级

@property (weak, nonatomic) IBOutlet UILabel *LevelOneLbl;

@property (weak, nonatomic) IBOutlet UILabel *LevelTwoLbl;

@property (weak, nonatomic) IBOutlet UILabel *LevelThree;






@end

@implementation XLMyLevelViewController
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self showBackButton:NULL];
    
    if ([[XLAccountManager shareInstance].model.IsAnchor isEqualToString:@"0"]) {
        self.navigationItem.title = @"用户等级";
        
        //等级特权
        self.teQunLbl.text = @"1、等级图标";
        self.TwoLbl.text = @"2、优先匹配权";
        self.ThreLbl.text = @"3、更多特权敬请期待";
        self.FourLbl.hidden = YES;
        
        //如何提升等级
        self.LevelOneLbl.text = @"1.消耗金豆（视频聊天、送礼物等）";
        self.LevelTwoLbl.text = @"2.完成每日任务和新手任务";
        self.LevelThree.hidden = YES;
        
    }else{
        self.navigationItem.title = @"主播等级";
        
        //等级特权
        self.teQunLbl.text = @"1、等级图标";
        self.TwoLbl.text = @"2、优先匹配土豪用户";
        self.ThreLbl.text = @"3、等级越高可以选择的视频聊天价格越多";
        self.FourLbl.text = @"4、更多特权敬请期待";
        
        //如何提升等级
        self.LevelOneLbl.text = @"1.增加视频聊天时间";
        self.LevelTwoLbl.text = @"2.获得更多礼物";
        self.LevelThree.text = @"3.收货用户好评数量";
    }

    
    _labelOnImage.text = F(@"Lv.%@",_mylevelNumber);
//    _MyJifenNumberLabel.text = F(@"我的积分:%@",_myJifenNumber);
    [self downloadUserInfor];
    
    self.view.backgroundColor = XLThemeColor;
    
    self.progressView.backgroundColor = [UIColor clearColor];
    self.progressView.layer.borderWidth = 1;
    self.progressView.layer.borderColor = [UIColor colorWithRed:255/255.0 green:187/255.0 blue:1/255.0 alpha:1].CGColor;
    
    
//    UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
//    button.frame = CGRectMake(0, 0, 50, 50);
//    [button setTitle:@"等级说明" forState:UIControlStateNormal];
//    [button addTarget:self action:@selector(levelDetail) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *rightBar1 = [[UIBarButtonItem alloc]initWithCustomView:button];
//    self.navigationItem.rightBarButtonItem = rightBar1;
}
-(void)downloadUserInfor{

    [[[XLHTTPSessionManager sharedManager] getMyLevelInforWithlevelNumber:_mylevelNumber lesvelType:[[[XLAccountManager shareInstance] model] IsAnchor]] subscribeNext:^(XLLevelInforModel *model) {
        _nextLevel.text = F(@"Lv.%ld(%@)",[_mylevelNumber integerValue]+1, model.EndValue);
//        _currentLevel.text = F(@"Lv.%@(%@)",_mylevelNumber,model.BeginValue);
//        _centerLevel.text = F(@"距离升级还差%ld积分",[model.EndValue integerValue] - [_myJifenNumber integerValue] );
        CGFloat floatNumber = ([_myJifenNumber integerValue] - [model.BeginValue integerValue]) * 1.0 / ([model.EndValue integerValue] - [model.BeginValue integerValue]);
        
        //距离某级别还差多少经验
        
        if ([[XLAccountManager shareInstance].model.IsAnchor isEqualToString:@"0"]) {
            self.MyJifenNumberLabel.text = F(@"距离LV.%ld还差%ld经验值", [_mylevelNumber integerValue]+1,[model.EndValue integerValue] - [_myJifenNumber integerValue]);
        }else{
            self.MyJifenNumberLabel.text = F(@"距离LV.%ld还差%ld魅力值", [_mylevelNumber integerValue]+1,[model.EndValue integerValue] - [_myJifenNumber integerValue]);
        }
        
        
        
        //设置宽度显示进度
        _progressViewWidth.constant = (SCREEN_WIDTH - 22) * floatNumber;
        
//        _pointViewOffSet.constant = (SCREEN_WIDTH - 22) * floatNumber -3;
    } error:^(NSError *error) {
        
    }];
}
- (void)levelDetail{
    XLWebViewController *vc = [[XLWebViewController alloc] init];
    vc.url = @"http://xinliao.interface.baomihua.com/taxXinLiao.html";
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
